package com.example.course_mangger_system.interceptor;

import org.springframework.web.servlet.HandlerInterceptor;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.util.Arrays;


public class LogInterceptor implements HandlerInterceptor {

    @Override
    public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) {

        // 在请求处理之前进行拦截
        System.out.println("=========================Request=====================");
        System.out.println("Request URL: " + request.getRequestURL().toString());
        System.out.println("Request Method: " + request.getMethod());
        System.out.print("Request Parameters: ");
        request.getParameterMap().forEach((key, value) -> System.out.println(key + "=" + Arrays.toString(value)));
        System.out.println("=========================Request END=====================");
        return true;
    }
}